<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>消息模板列表</title>
    <!--{include file="comm/icheck.tpl"}-->
</head>
<body>

<div class="container">
    
        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" onsubmit="return false;" id="search_form">
                        <table>
                            <tbody>
                            <tr>
                                <td height="27px">
                                    <span>模板名称：<input type="text" class="form-control input-sm" style="width:148px" value="" name="templateName" id="templateName"></span>

                                    <span><input type="button" onclick="messageTemplate.search();" class="btn btn-primary" value="查询"></span>
                                    <span><input type="button" onclick="messageTemplate.reSet();" class="btn btn-warning" value="重置"></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none;"></table>

        </div>


</div>
<script type="text/javascript">


$("#flex").flexigrid({
    url:"/invokingAjax-backend/system/messageTemplate.ajax?operFlg=1",
    dataType: "json",
    colModel : [
        {display: "操作", width : 120, align: "center"},
        {display: "模板名称",width : 240,align:"left",name : "createTime", sortable : true},
        {display: "模板别名", width : 240,align:"left"},
        {display: "模板类型", width : 120,align:"center"}
    ],
    buttons : [
        {name: "添加", bclass: "add", onpress:"messageTemplate.messageTemplateAdd"},
        {separator: true},
        {name: "删除", bclass: "delete", onpress : "messageTemplate.delcheck"},
        {separator: true},
        {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
        {separator: true},
        {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
    ],
    sortname: "createTime",
    sortorder: "desc",
    usepager: true,
    rp: 20,
    useRp: true,
    showTableToggleBtn: true,
    onSubmit: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt});
        return true;
    }
});

var messageTemplate= {

    delArr: new Array(),//删除数组变量定义



    //头部 按条件查询
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({params: dt}).flexReload();
    },


    //删除确认
    delcheck: function(){
        //获取选中的行的行数
        var selected_count = $('.trSelected',flex).length;
        if (selected_count==0) {
            E.alert("请选择要删除的模板");
            return;
        }else{
            var tempArr = new Array();
            for(var i=0; i<selected_count; i++){
                var templateIDStr = $('.trSelected',flex).eq(i).attr('id');
                var templateIDStr = templateIDStr.substr(3);
                tempArr.push(templateIDStr);
            }
            this.delArr = tempArr;
            E.confirm('确认删除这 ' + $('.trSelected',flex).length + ' 个模板吗?', "messageTemplate.del");
        }
    },

    //删除执行
    del:function(){
        $.ajax({
            type: "POST",
            url: "/invokingAjax-backend/system/messageTemplate.ajax?operFlg=3",
            dataType: "JSON",
            data:{delArr: messageTemplate.delArr},
            success: function(result_obj){
                if (result_obj.code == 200) {
                    E.alert(result_obj.message, 2, "messageTemplate.load");
                }
                else {
                    E.alert(result_obj.message);
                }
            }
        });
    },


    //重新加载
    load: function() {
        $("#flex").flexReload();
    },


    //对ajax返回的信息进行提示
    msg: function( obj ) {
        if( obj.code == 200 ){
            E.loadding.close();
            E.alert( obj.message , 2 , 'wechatActivityList.load');
        }else{
            E.loadding.close();
            E.alert(obj.message);
        }
    },


    //自定义模板添加
    messageTemplateAdd:function(){
        E.open("/quanliadmin/app/system/messageTemplate.pscript?operFlg=2", "" , {height: 540,width: 980, top: 100, left: 200});

    },

    //编辑自定义模板
    messageTemplateEdit:function(templateID){
        E.open("/quanliadmin/app/system/messageTemplate.pscript?operFlg=3&templateID="+templateID, "" , {height: 540,width: 980, top: 100, left: 200});

    },

    //重置
    reSet:function(){
        $("#templateName").val('');
        $("#type").val('');
        messageTemplate.load();
    }


};


function jquery_ajax(flg,data,func){//ajax的jQuery封装
    $.ajax({
        type: "post",
        url: "/invokingAjax-backend/wechatPromotion/wechatActivity.ajax?operFlg="+flg,
        dataType: "json",
        data: data,
        success: function( result_obj ) {
            func(result_obj);
        },
        error : function(msg){
            alert('网络不给力，请重新尝试...');
        }
    });
}


</script>

</body>
</html>